import { ViewAction, ViewActionTypes } from '../actions/view.action';
import { ViewModel } from '../../models';

export interface ViewState {
    entities: ViewModel
}

export const initialViewState: ViewState = {
    entities: {
        center: [0, 0],
        zoom: 0,
        minZoom: 0,
        maxZoom: 0,
        disabledZoomIn: false,
        disabledZoomOut: false
    }
}

export function ViewReducer(state: ViewState = initialViewState, action: ViewAction): ViewState {
    switch(action.type) {
        case ViewActionTypes.VIEW_UPDATE: {
            return {
                entities: action.payload
            };
        }
        case ViewActionTypes.VIEW_CENTER: {
            const center = action.payload;
            const entities = { ...state.entities, center };
            return { entities };
        }
        case ViewActionTypes.VIEW_DISABLED_ZOOM_IN: {
            const disabledZoomIn = action.payload;
            const entities = { ...state.entities, disabledZoomIn };
            return { entities };
        }
        case ViewActionTypes.VIEW_DISABLED_ZOOM_OUT: {
            const disabledZoomOut = action.payload;
            const entities = { ...state.entities, disabledZoomOut };
            return { entities };
        }
        case ViewActionTypes.VIEW_MAXZOOM: {
            const maxZoom = action.payload;
            const entities = { ...state.entities, maxZoom };
            return { entities }
        }
        case ViewActionTypes.VIEW_MINZOOM: {
            const minZoom = action.payload;
            const entities = { ...state.entities, minZoom };
            return { entities };
        }
        case ViewActionTypes.VIEW_ZOOM: {
            const zoom = action.payload;
            const entities = { ...state.entities, zoom };
            return { entities };
        }
        default: {
            return state;
        }
    }
}